module mesh_dump_mod

use global_mod
use lib_vtk_io

use mesh_mod,       only: MeshObj
use utils_misc_mod, only: Critical_Error, ARROW_ERR_DMP_VTKINI, ARROW_ERR_DMP_VTKMSH, ARROW_ERR_DMP_VTKCLS

implicit none

logical           :: zOn      = .false.    !< is the dump on
character(len=16) :: filename = "mesh.xml" !< default filename
character(len=16) :: method   = "vtk"      !< use VTK format - no others available yet

namelist /mesh_dump/  zOn, filename, method

interface Mesh_Write
  module procedure Mesh_Write_VTK
end interface

contains

integer function File_Init_VTK(filename, nx, ny, nz)
    character(len=*), intent(in) :: filename
    integer, intent(in) :: nx
    integer, intent(in) :: ny
    integer, intent(in) :: nz
    err_io = VTK_INI_XML('ascii', filename, 'RectilinearGrid',1,nx,1,ny,1,nz)
end function File_Init_VTK

subroutine Mesh_Write_VTK(mesh)
  type(MeshObj), intent(in) :: mesh

!  err_io = VTK_INI_XML('ascii', filename, 'RectilinearGrid', &
!                       1,mesh%nNodes_x, &
!                       1,mesh%nNodes_y, &
!                       1,mesh%nNodes_z
!  if (err_io/=0) call Critical_Error(ARROW_ERR_DMP_VTKINI, "Mesh_Write_VTK")
!
!  err_io = VTK_GEO_XML(1,mesh%nNodes_x, &
!                       1,mesh%nNodes_y, &
!                       1,mesh%nNodes_z, &
!                       mesh%axis_x, &
!                       mesh%axis_y, &
!                       mesh%axis_z)
!  if (err_io/=0) call Critical_Error(ARROW_ERR_DMP_VTKMSH, "Mesh_Write_VTK")

!  err_io = VTK_GEO_XML()
!  if (err_io/=0) call Critical_Error(ARROW_ERR_DMP_VTKMSH, "Mesh_Write_VTK")

!  err_io = VTK_END_XML()
!  if (err_io/=0) call Critical_Error(ARROW_ERR_DMP_VTKCLS, "Mesh_Write_VTK")
end subroutine Mesh_Write_VTK

end module mesh_dump_mod
